package com.shigen.demo.rocksdb;

import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;

import javax.annotation.Resource;

// @Service
public class RocksDBService {

    @Resource
    private RocksDB rocksDB;

    public void putData(String key, String value) throws RocksDBException {
        rocksDB.put(key.getBytes(), value.getBytes());
    }

    public String getData(String key) throws RocksDBException {
        byte[] valueBytes = rocksDB.get(key.getBytes());
        return valueBytes != null ? new String(valueBytes) : null;
    }

    public void updateData(String key, String value) throws RocksDBException {
        rocksDB.put(key.getBytes(), value.getBytes());
    }

    public void deleteData(String key) throws RocksDBException {
        rocksDB.delete(key.getBytes());
    }
}
